package com.qfedu.filter;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 创建者: QF-SUN
 * 创建时间: 2023/3/27 10:19
 * 描述: 编码过滤器
 */
//@WebFilter("/*")
public class CharacterEncodingFilter  implements Filter {
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {

    }

    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        HttpServletRequest request = (HttpServletRequest) servletRequest;
        HttpServletResponse response = (HttpServletResponse) servletResponse;

        request.setCharacterEncoding("utf-8");
        System.out.println("编码过滤器执行了");

        //放行， 执行下一个过滤器
        filterChain.doFilter(request, response);
    }

    @Override
    public void destroy() {

    }
}
